﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Manager_MemberIndex : System.Web.UI.PageEx
{
    private string strPageCode = "M00001";
    private string strLoginResult = string.Empty;
    private int iLoginUserId = 0;

    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strQuery = " and 1=1";

    private string strSelectId = string.Empty;

    private Model.DbSystem dbSystem = Dal.DbSystemDal.Select(1);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        int.TryParse(Convert.ToString(Session["UserId"]), out iLoginUserId);
        strSelectId = Convert.ToString(Request.QueryString["Mid"]);
    }
    private void DataBinds(int iSelectTab)
    {
        int iSelectId = 0;
        int.TryParse(strSelectId, out iSelectId);
        DataSet ds = null;
        ds = DalEx.DbUserDalEx.Select(" and UserId=" + iSelectId);
        if (SqlHelper.HasRow(ds))
        {
            Model.DbUsers dbUsers = new Model.DbUsers(ds.Tables[0].Rows[0]);
            switch (iSelectTab)
            {
                case 0://绑定会员基本信息
                    lblUserTitle.Text = Convert.ToString((Sex)dbUsers.Sex);
                    lblUserName.Text = dbUsers.UserName;
                    lblTrueName.Text = dbUsers.FirstName + " " + dbUsers.LastName;
                    lblRegisterDate.Text = dbUsers.AddTime.ToString("MM/dd/yyyy HH:mm:ss");
                    lblRegisterIP.Text = dbUsers.FirstIP;
                    lblLastLoginDate.Text = dbUsers.LastLoginTime.ToString("MM/dd/yyyy HH:mm:ss");
                    lblLastLoginIP.Text = dbUsers.LastIP;
                    lblLoginTimes.Text = dbUsers.LoginTimes.ToString();
                    lblTel.Text = dbUsers.Tel;
                    lblAddress.Text = dbUsers.Address;
                    //lbtnSendMail.i

                    ds = DalEx.BaoMingEx.Select(" and UserId=" + dbUsers.UserID);
                    lblBaoMingCounts.Text = ds.Tables[0].Rows.Count.ToString();
                    ds = DalEx.BaoMing2Ex.Select(" and UserId=" + dbUsers.UserID);
                    lblYiGongBaoMingCounts.Text = ds.Tables[0].Rows.Count.ToString();
                    ds = DalEx.BaoMing3Ex.Select(" and UserId=" + dbUsers.UserID);
                    lblHomeEventBaoMingCounts.Text = ds.Tables[0].Rows.Count.ToString();

                    break;
                case 1:
                    hfMemberID.Text = dbUsers.UserID.ToString();
                    break;
            }
        }
    }
    protected void TabStrip1_TabIndexChanged(object sender, EventArgs e)
    {
        DataBinds(TabStrip1.ActiveTabIndex);
    }
    protected void btnChangePwd_Click(object sender, EventArgs e)
    {
        string strResult = string.Empty;
        int iSelectId = 0;
        int.TryParse(hfMemberID.Text, out iSelectId);
        string strPwd = SqlHelper.String(txtNewPassword.Text);
        Model.DbUsers dbUsers = DalEx.DbUserDalEx.Select(iSelectId);
        if (dbUsers != null)
        {
            dbUsers.UserPwd = SqlHelper.MD5(strPwd, 32);
            if (DalEx.DbUserDalEx.ChangePwd(dbUsers, ref strResult))
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Information);
            }
            else
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Information);
            }
        }
    }
}
